package com.nescafe.nescafepromo.entity;

import java.text.ParseException;
import java.util.Date;

import com.google.appengine.api.datastore.Entity;
import com.google.appengine.api.datastore.Key;
import com.nescafe.nescafepromo.util.FormatUtil;

public class ExtraPoint extends NPEntity {

	public static final String DATE_FIELD = "shoutDate";
	private long date = 0;
	private Key parent = null;

	public ExtraPoint(int date, Key parent) {
		this.date = date;
		this.parent = parent;
	}

	public ExtraPoint(Entity entity) {
		this.parent = entity.getParent();
		this.date = (int) entity.getKey().getId();
	}

	public long getDate() {
		return date;
	}

	public String getDisplayDate() {
		String displayDate = "";
		try {
			Date d = FormatUtil.dbDateFormat.parse(String.valueOf(date));
			if (d != null) {
				displayDate = FormatUtil.displayDateFormt.format(d);
			}
		} catch (ParseException e) {

		}
		return displayDate;
	}

	public Key getParent() {
		return parent;
	}

	@Override
	public Entity toEntity() {
		Entity e = new Entity(EntityType.EXTRA_POINT.getKind(), date, parent);
		e.setProperty(DATE_FIELD, date);
		return e;
	}

}
